﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfAndEcharts
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            //Register a host instance for methods to be called from javascript
            Web.ObjectForScripting = new WebAdapter();            
        }

        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            Web.Navigate(new Uri(Directory.GetCurrentDirectory() + "/Resources/index.html"));
        }

        private void OnLoadButtonClick(object sender, RoutedEventArgs e)
        {
            if (Web.IsLoaded)
            {
                //Call javascript method
                Web.InvokeScript("showMsg", "A message from web page");
            }
        }

        private void OnBrowserSizeChanged(object sender, SizeChangedEventArgs e)
        {
            var document = Web.Document as mshtml.HTMLDocument;
            if (document != null)
            {
                var element = document.getElementById("main");
                element.style.width = e.NewSize.Width - 50;
                element.style.height = e.NewSize.Height - 50;                
            }
        }
    }
}
